package Dao;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import Bean.JoinBean;
import Bean.MemberBean;

public class MemberDao extends SqlMapClientDaoSupport{
	
	public int mLogin(MemberBean bean) {
		MemberBean member = (MemberBean)getSqlMapClientTemplate().queryForObject("mLogin", bean);
		String pw = bean.getM_pw();
		String id= bean.getM_id();
		System.out.println("멤버 다오 넘어온것:"+pw);
		System.out.println("멤버 다오 넘어온것:"+id);
		if (member!=null) {
			if (pw.equals(member.getM_pw())) {
				return 1;
			} else {
				return 0;
			}
		} else {
			return -1;
		}
	}
	public int mCheckid(MemberBean bean) {

		MemberBean member = (MemberBean)getSqlMapClientTemplate().queryForObject("mCheckid", bean);
		String id = bean.getM_id();
		if (member!=null) {
			if (id.equals(member.getM_id())) {
				return 1;
			}else {
			return 0;
			}
		}else{
			return -1;
		}
	}
	
	public int mChecknickname(MemberBean bean) {

		MemberBean member = (MemberBean)getSqlMapClientTemplate().queryForObject("mChecknickname", bean);
		System.out.println("쿼리 실행 성공!!");
		String nickname = bean.getM_nickname();
		if (member!=null) {
			if (nickname.equals(member.getM_nickname())) {
				return 1;
			}else {
			return 0;
			}
		}else{
			return -1;
		}
	}
	
	public int mCheckemail(MemberBean bean) {

		MemberBean member = (MemberBean)getSqlMapClientTemplate().queryForObject("mCheckemail", bean);
		String email = bean.getM_email();
		System.out.println();
		if (member!=null) {
			if (email.equals(member.getM_email())) {
				return 1;
			}else {
				return 0;
				}
		}else{
			return -1;
		}
	}
	
	public void mInsert(MemberBean bean) {
		getSqlMapClientTemplate().insert("mInsert", bean);
	}
	public MemberBean mSearchID(MemberBean bean){
		return (MemberBean)getSqlMapClientTemplate().queryForObject("mSearchId", bean);
	}
	
	public MemberBean mSearchPW(MemberBean bean){
		return (MemberBean)getSqlMapClientTemplate().queryForObject("mSearchPw", bean);
	}
	
	public MemberBean mUpdateForm(MemberBean myinfo){
		return (MemberBean)getSqlMapClientTemplate().queryForObject("mCheckid", myinfo);
	}
	
	public void mUpdate(MemberBean bean){
		getSqlMapClientTemplate().update("mUpdate", bean);
	}
	
	public List mBuylist(String m_id){
		return (List<JoinBean>)getSqlMapClientTemplate().queryForList("getBuylistjoin" , m_id);
	}
	
}
